#include "stdafx.h"
#include "spell.h"
#include <math.h>

const float Spell::FIREBALL_SPEED = 10.0;
const float Spell::FROSTBALL_SPEED = 15.0;
const float Spell::MAGIC_ARROW_SPEED = 20.0;

static const float CAST_OFFSET = 80;

namespace {

vec2f getPosition(const IUnit *caster)
{
    vec2f pos(caster->x(), caster->y());
    pos.x += CAST_OFFSET * cos(caster->direction());
    pos.y -= CAST_OFFSET * sin(caster->direction());

    return pos;
}

}

Spell::Spell(const IUnit *caster, SpellKind kind) :
    MovingObject(getPosition(caster), caster->direction()),
    _kind(kind)
{
    init();
}

Spell::~Spell()
{
}

Spell::SpellKind Spell::kind() const
{
    return _kind;
}

void Spell::accept(ISceneObjectVisitor *visitor)
{
    visitor->visit(this);
}

void Spell::init()
{
    setRadius(20.0);
    switch (_kind)
    {
        case FIREBALL:
            setSpeed(FIREBALL_SPEED);
            break;
        case FROSTBALL:
            setSpeed(FROSTBALL_SPEED);
            break;
        case MAGIC_ARROW:
        default:
            setSpeed(MAGIC_ARROW_SPEED);
            break;
    }
}
